package com.vma.tools.wxGZH;

import com.google.gson.Gson;
import com.jfinal.kit.HttpKit;
import net.sf.json.JSONObject;

/**
 * Created by chenzui on 2017/8/2.
 */
public class WxGzhUtils {
    public static String appId="wx70d52cbcf5ced465";

    public static String secret="9fe72e211b2bdf24fcf141a570ed056d";

    public static WebAccessToken getAccessToken(String code){
//        String s = HttpKit.get("https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxae1517e773b9edfe&secret=cf8d13036c2230652197cb66409b37b4&code=081Fk6u01FaWu12kZku01nJ8u01Fk6u9&grant_type=authorization_code");
        String s = HttpKit.get("https://api.weixin.qq.com/sns/oauth2/access_token?appid="+appId+"&secret="+secret+"&code="+code+"&grant_type=authorization_code");
        System.out.println(s);
        return new Gson().fromJson(s,WebAccessToken.class);
    }

    public static String globalAccessToken(){
        String s = HttpKit.get("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+secret);
        System.out.println(s);
        return new Gson().fromJson(s,GlobalAccessToken.class).getAccess_token();
    }

    public static void refreshToken(String refreshAccessToken){
        String s = HttpKit.get("https://api.weixin.qq.com/sns/oauth2/refresh_token?appid="+appId+"&grant_type="+refreshAccessToken+"&refresh_token=REFRESH_TOKEN");
    }

    public static UserInfo userInfo(String accessToken,String openId){
        String s = HttpKit.get("https://api.weixin.qq.com/sns/userinfo?access_token="+accessToken+"&openid="+openId+"&lang=zh_CN");
        System.out.println(s);
        return new Gson().fromJson(s,UserInfo.class);
    }

    public static void checkAccessToken(String accessToken,String openId){
        String s = HttpKit.get("https://api.weixin.qq.com/sns/auth?access_token="+accessToken+"&openid="+openId+"&lang=zh_CN");
        System.out.println(s);
    }

    public static JsApiTicket getTicket(String accessToken){
        String s = HttpKit.get("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token="+accessToken+"&type=jsapi");
        System.out.println(s);
        return new Gson().fromJson(s,JsApiTicket.class);
    }
    public static void main(String[] args){
//        WebAccessToken accessToken = getAccessToken();
        checkAccessToken("HfuIMJgrnoJBtmHX2VcM8rMwaC1ltEhIgC8Y2R3g72830aEmCMovZgT0CELbWqRSDOxxQUb0FWzpiYt-51YJgMF8y8Vr9Fk7x68bBi8MK0Y","osf44v582rXwy5fe-bjsYkVqfQjo");
//        userInfo(accessToken.getAccessToken(),accessToken.getOpenid());
        userInfo("HfuIMJgrnoJBtmHX2VcM8rMwaC1ltEhIgC8Y2R3g72830aEmCMovZgT0CELbWqRSDOxxQUb0FWzpiYt-51YJgMF8y8Vr9Fk7x68bBi8MK0Y","osf44v582rXwy5fe-bjsYkVqfQjo");

    }
}
